package com.aneliya.client.tcp;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

import com.aneliya.client.ClientListener;
import com.aneliya.client.ClientSender;
import com.aneliya.client.IClient;
import com.aneliya.model.Message;

public class TCPClient implements IClient {
	private Socket socket;
	public Socket getSocket() {
		return socket;
	}
	public void setSocket(Socket socket) {
		this.socket = socket;
	}
	
	private TCPClientListener listener;
	public void setClientListener(ClientListener listener) {
		this.listener = (TCPClientListener) listener;
	}
	
	private TCPClientSender sender;
	public void setClientSender(ClientSender sender) {
		this.sender = (TCPClientSender) sender;
	}
	
	private String username;
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	
	public InputStream getInputStream() throws IOException {
		return socket.getInputStream();
	}
	
	public OutputStream getOutputStream() throws IOException {
		return socket.getOutputStream();
	}
	
	public void interruptClientListener() {
		listener.interrupt();
	}
	
	public void interruptClientSender() {
		sender.interrupt();
	}
	
	public void sendMessage(Message message) {
		sender.sendMessage(message);
	}
	
	public void sendKeepAliveMessage() {
		sender.sendKeepAlive();
	}

	public void start() {
		listener.start();
		sender.start();
	}
	
}
